package com.gitee.es.dynamics.common;

import java.util.Enumeration;
import java.util.concurrent.ConcurrentHashMap;

public class LocalCache {
    private final static ConcurrentHashMap<String, Object> concurrentHashMap = new ConcurrentHashMap<>();

    public static Object put(String key, Object val) {
        return concurrentHashMap.put(key, val);
    }

    public static Object get(String key) {
        return concurrentHashMap.get(key);
    }

    public static String toCacheString() {
        return concurrentHashMap.toString();
    }

    public static void removeByKeyPrefix(String prefix) {
        Enumeration<String> keys = concurrentHashMap.keys();
        while (keys.hasMoreElements()) {
            String key = keys.nextElement();
            if (key.startsWith(prefix)) {
                concurrentHashMap.remove(key);
            }

        }

    }


}
